package com.wsoft.im.util;

import com.wsoft.core.utils.LoginUserUtil;
import com.wsoft.im.entity.ImGroupMemberEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author z001
 * @Date 2025/1/14 18:45
 */
public class GroupMemberUtil {


    /**
     * 新增群成员列表
     * @param groupId
     * @param memberIdList
     * @param isAddOwn 是否添加当前用户为群主
     * @return
     */
    public static List<ImGroupMemberEntity> buildGroupMember(Long groupId, List<Long> memberIdList, boolean isAddOwn){
        List<ImGroupMemberEntity> groupMemberList = new ArrayList<>();

        Long curMemberId = LoginUserUtil.getUserInfo().getLoginUserVO().getId();
        for (Long memberId : memberIdList) {
            ImGroupMemberEntity groupMemberEntity = new ImGroupMemberEntity();
            groupMemberEntity.setGroupId(groupId);
            groupMemberEntity.setMemberId(memberId);
            groupMemberEntity.setIsGroupLeader(0);
            groupMemberEntity.setIsTip(0);
            groupMemberEntity.setInviteMemberId(curMemberId);
            groupMemberList.add(groupMemberEntity);
        }
        if(isAddOwn){
            //当前人为群主
            ImGroupMemberEntity groupMemberEntity = new ImGroupMemberEntity();
            groupMemberEntity.setGroupId(groupId);
            groupMemberEntity.setMemberId(curMemberId);
            groupMemberEntity.setIsGroupLeader(1);
            groupMemberEntity.setIsTip(0);
            groupMemberList.add(groupMemberEntity);
        }
        return groupMemberList;
    }
}
